package ar.com.ironsoft.javaopenauth.utils;

import org.apache.commons.lang.StringUtils;

/**
 * Util class to validate data.
 * 
 * @author Tomas de Priede
 * @version 0.1.2, 05/02/2011
 * @since 0.1.2-SNAPSHOT
 */
public class ValidatorUtils {

	/**
	 * Ckeck if the object is null and throw exception.
	 * 
	 * @param obj the object to validate
	 * @throws java.lang.IllegalArgumentException
	 * @author Tomas de Priede
	 * @version 0.1.2, 05/02/2011
	 * @since 0.1.2-SNAPSHOT
	 */
	public static void validateNull(Object obj) {
		if (obj == null) {
			throw new IllegalArgumentException("object is null");
		}
	}

	/**
	 * Check if the string is null or empty and throw exception.
	 * @param s the String to validate
	 * @throws java.lang.IllegalArgumentException
	 * @author Tomas de Priede
	 * @version 0.1.2, 05/02/2011
	 * @since 0.1.2-SNAPSHOT
	 */
	public static void validateEmpty(String s) {
		validateNull(s);
		if (StringUtils.isEmpty(s)) {
			throw new IllegalArgumentException("Empty string");
		}
	}

	/**
	 * Check if the objects are null or emptys. 
	 * @param objs the objects to validate
	 * @throws java.lang.IllegalArgumentException
	 * @author Tomas de Priede
	 * @version 0.1.2, 05/02/2011
	 * @since 0.1.2-SNAPSHOT
	 */
	public static void validateNullOrEmpty(Object... objs) {
		validateNull(objs);

		for (Object o : objs) {
			validateNull(o);
			if (o instanceof String) {
				String s = (String) o;
				validateEmpty(s);
			}
		}
	}
}
